package logic

import (
	"context"
	"doctor-system/doctorrpc/doctorrpcclient"

	"doctor-system/api/internal/svc"
	"doctor-system/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddDoctorLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddDoctorLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddDoctorLogic {
	return &AddDoctorLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddDoctorLogic) AddDoctor(req *types.AddDoctorRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	doctor, err := l.svcCtx.DoctorRpc.AddDoctor(l.ctx, &doctorrpcclient.AddDoctorRequest{
		Name:            req.Name,
		Image:           req.Image,
		Hospital:        req.Hospital,
		RegisterFee:     float32(req.RegisterFee),
		ConsultationFee: float32(req.ConsultationFee),
		Profile:         req.Profile,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "医师添加成功",
		Data:    doctor,
		Code:    200,
	}, nil
}
